﻿using JESAI.Redis.Enums;
using JESAI.Redis.Events;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using JESAI.Redis.Attributes;
using JESAI.Redis.Datas;

namespace JESAI.Redis.Abstracts.Commands
{
    public interface IRedisCommand
    {
        #region Events

        /// <summary>
        /// 
        /// </summary>
        /// <param name="eventHandler"></param>
        void RegisterCommandExecuteEvent(EventHandler<CommandExecuteEventArgs> eventHandler);
        /// <summary>
        /// 注册命令拦截
        /// </summary>
        /// <param name="eventHandler"></param>
        void RegisterCommandExecutedEvent(EventHandler<CommandExecutedEventArgs> eventHandler);

        /// <summary>
        /// 取消注册拦截器
        /// </summary>
        void UnRegisterCommandExecuteEvent(EventHandler<CommandExecuteEventArgs> eventHandler);

        /// <summary>
        /// 取消注册拦截器
        /// </summary>
        void UnRegisterCommandExecutedEvent(EventHandler<CommandExecutedEventArgs> eventHandler);

        #endregion

        /// <summary>
        /// 存储字符串
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="timeSpan"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [RedisIdentification(RedisVersionSupportEnum.Version_1_0_0, TimeComplexityEnum.O1)]
        Task<bool> SetAsync(string key, object value, TimeSpan expiryTime = default, CancellationToken cancellationToken = default);

        /// <summary>
        /// 查询字符串
        /// </summary>
        /// <param name="key"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [RedisIdentification(RedisVersionSupportEnum.Version_1_0_0, TimeComplexityEnum.O1)]
        Task<RedisData> GetAsync(string key, CancellationToken cancellationToken = default);
    }
}
